package com.cuit.bysj.action;

import com.cuit.bysj.entities.Appraise;
import com.cuit.bysj.entities.TcherResults;
import com.cuit.bysj.entities.Teacher;
import com.cuit.bysj.entities.User;
import com.cuit.bysj.service.TcherService;
import com.cuit.bysj.utils.JsonHelper;
import com.cuit.bysj.utils.Result;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import net.sf.json.JSONObject;

public class TcherManageAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String result;
	private TcherService tcherService;
	private String id;
	private String tid;
	private String msg;
	private String cname;
	private String banji;
	private String academic;
	private String college;

	public String getAcademic() {
		return academic;
	}

	public void setAcademic(String academic) {
		this.academic = academic;
	}

	public String getCollege() {
		return college;
	}

	public void setCollege(String college) {
		this.college = college;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getBanji() {
		return banji;
	}

	public void setBanji(String banji) {
		this.banji = banji;
	}

	public String getCname() {
		return cname;
	}

	public void setCname(String cname) {
		this.cname = cname;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public String getTid() {
		return tid;
	}

	public void setTid(String tid) {
		this.tid = tid;
	}

	public TcherService getTcherService() {
		return tcherService;
	}

	public void settcherService(TcherService tcherService) {
		this.tcherService = tcherService;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public String getResult() {
		return result;
	}

	public String openpage() {
		Result<User> Userresult = new Result<User>();
		Userresult.setSuccess(true);
		Userresult.setUrl("TcherlistPage");

		result = JSONObject.fromObject(Userresult).toString();

		return "json";
	}

	@SuppressWarnings("unchecked")
	/*
	 * 加载教师列表
	 */
	public String loadTcherlist() {
		Result<Teacher> Tcherresult = new Result<Teacher>();

		Tcherresult.setItems(tcherService.tcherlist());

		result = JsonHelper.getJsonHelper().format(Tcherresult);

		return "json";
	}

	public String loadTableByTcherId() {
		Result<Appraise> Tcherresult = new Result<Appraise>();

		Tcherresult.setItems(tcherService.findListbyTcherId(tid, cname, banji));
		Tcherresult.setUrl("AppraiseList");

		result = JsonHelper.getJsonHelper().format(Tcherresult);

		return "json";
	}

	public String loadTcherSeeList() {
		Result<TcherResults> Tcherresult = new Result<TcherResults>();

		User user = (User) ActionContext.getContext().getSession().get("User");
		Tcherresult.setItems(tcherService.initTcherSeelist(user.getTeacher().getId()));

		result = JsonHelper.getJsonHelper().format(Tcherresult);

		return "json";
	}

	public String findTcher() {
		Result<Teacher> tcherresult = new Result<Teacher>();

		tcherresult.setItem(tcherService.findTcher(Integer.parseInt(id)));

		result = JsonHelper.getJsonHelper().format(tcherresult);

		return "json";
	}

	public String updatetcher() {
		Result<Teacher> tcherresult = new Result<Teacher>();

		Teacher tcher = tcherService.findTcher(Integer.parseInt(id));
		tcher.setTname(cname);
		tcher.setAge(banji);
		tcher.setTid(tid);
		tcher.setSex(msg);
		tcher.setAcademic(academic);
		tcher.setCollege(college);
		tcherService.updateTcher(tcher);
		tcherresult.setMsg("修改成功");

		result = JsonHelper.getJsonHelper().format(tcherresult);

		return "json";
	}
}
